package br.com.jk.uf;

import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author camilo
 */
public class UfDaoHibernate implements UfDao {

  private Session session;
  private Transaction transacao;

  public void setSession(Session session) {
    this.session = session;
  }

  @Override
  public void salvar(Uf uf) {
    this.transacao = this.session.beginTransaction();
    this.session.saveOrUpdate(uf);
    this.transacao.commit();
    this.session.close();
  }

  @Override
  public void excluir(Uf uf) {
    this.transacao = this.session.beginTransaction();
    this.session.delete(uf);
    this.transacao.commit();
    this.session.close();
  }

  @Override
  public Uf carregar(int id) {
    return (Uf) this.session.get(Uf.class, id);
  }

  @Override
  public List<Uf> listar() {
    return this.session.createCriteria(Uf.class).list();
  }
}
